#include <stdio.h>
#include "reg.h"
#include "verilated_dpi.h"

//get reg data from DPC-C
uint64_t *csrs_pt = NULL;
extern "C" void set_csrs_ptr(const svOpenArrayHandle r) {
csrs_pt = (uint64_t *)(((VerilatedDpiOpenVar*)r)->datap());
}

//get reg data from DPC-C
uint64_t *cpu_gpr = NULL;
extern "C" void set_gpr_ptr(const svOpenArrayHandle r) {
cpu_gpr = (uint64_t *)(((VerilatedDpiOpenVar*)r)->datap());
}
					  
const char *regs[] = {
  "$0", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
  "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
  "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
  "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"
};

void reg_display() {
	for(int i=0;i<32;i++){
	printf("%s:%lx\n",regs[i],gpr(i));
	}
}

word_t reg_str2val(const char *s, bool *success) {
	for(int i=0;i<32;i++){
		if(strcmp(s,regs[i]) == 0){
			*success = true;
			return gpr(i);
		}
	}
	*success = false;
	return 0;
}
 
